<script type="text/ecmascript-6">
   import Navbar from '../../components/base/navbar.vue';
   export default{
       name:"coupon-detail",
       components:{
           Navbar
       },
       data(){
           return {
               myID:this.$route.params.id
           }
       },
       methods:{
         jump(page, id) {
           this.$router.push({ name: page, params: {id: id} });
         }
       },
       mounted(){
           this.$store.dispatch('queryCouponDetail',this.myID);
       },
       computed: {
         statusDisabled: function() {
           const end = this.detail.ends_at;
           if(!end) return;
           const isUsed = this.detail.used_at,
             time = new Date(end.replace(/-/g,"/")).getTime() - new Date().getTime();
           if( isUsed!='' || time<0 ){
             return true;
           }else{
             return false;
           }
         },
         statusTxt: function () {
           const end = this.detail.ends_at;
           if(!end) return;
           const isUsed = this.detail.used_at,
             time = new Date(end.replace(/-/g,"/")).getTime() - new Date().getTime();
           switch (true) {
             case isUsed!='':
               return '已使用';
             case time<0:
               return '已过期';
             default:
               return '立即使用';
           }
         },
         detail:{
             get(){
                 return this.$store.getters.getCouponDetail
             }
         }
       },
   }
</script>
